from manim import *



class math1(MovingCameraScene):
    def construct(self):
        self.camera.background_color = BLACK  # 设置背景颜色
        self.camera.frame_width = 100  # 设置边框宽度
        self.camera.frame_height = 60  # 设置边框高度
        self.camera.pixel_height = 1080  # 设置像素高度
        self.camera.pixel_width = 1920  # 设置像素宽度
        self.camera.center = ORIGIN  # 设置中心点位置
        self.camera.scale_factor = 1.0  # 设置缩放因子
        #设置横线
        for i in range(6*2+1):       
            dot1=Dot([-50,5*(i-6),0]).set_opacity(0.5)
            dot2=Dot([50,5*(i-6),0]).set_opacity(0.5)
            if i==6:
                line1=Line(dot1,dot2).set_color(WHITE).set_opacity(0.5)
                
            else:
                line1=Line(dot1,dot2).set_color(WHITE).set_opacity(0.5)
               
            self.add(dot1,dot2,line1)
        #设置竖线
        for i in range(10*2+1):        
            dot3=Dot([(i-10)*5,-30,0]).set_opacity(0.5)
            dot4=Dot([(i-10)*5,30,0]).set_opacity(0.5)
            if i==10:
                line2=Line(dot3,dot4).set_color(WHITE).set_opacity(0.5)
                
            else:
                line2=Line(dot3,dot4).set_color(WHITE).set_opacity(0.5)
            self.add(dot3,dot4,line2)
        #设置三个点
        dot1 = Dot(radius=1, color=RED)  
        dot1.move_to([-47.5,27.5,0]) 
        dot2 = Dot(radius=1, color=YELLOW)  
        dot2.move_to([-42.5,27.5,0])  
        dot3 = Dot(radius=1, color=GREEN)  
        dot3.move_to([-37.5,27.5,0])
        #镜头跟进效果 
        self.camera.frame.save_state()
        #题目出现
        self.play(self.camera.frame.animate.scale(1).move_to([0,0,0]))
        text = Tex(r"\text{设函数}$f\left( x,y\right) $\text{在}$\left( 0,0\right) $\text{的某领域连续,且}$\lim\limits _{\left( x,y\right) \rightarrow \left( 0,0\right) }\dfrac{f\left( x,y\right) -f\left( 0,0\right) }{x^{3}+y^{3}-3x^{2}-3y^{2}}=1$\text{则:}"
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([0,20,0])
        text1 = Tex(r"\text{(A)点}$\left( 0,0\right)$\text{不是}$f\left( x,y\right) $\text{的极值点}"
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-23,12,0])
        text2 = Tex(r"\text{(B)点}$\left( 0,0\right)$\text{是}$f\left( x,y\right) $\text{的极大值点}"
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([23,12,0])
        text3 = Tex(r"\text{(C)点}$\left( 0,0\right)$\text{是}$f\left( x,y\right) $\text{的极小值点}"
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-23,7,0])
        text4 = Tex(r"\text{(D)无法判断点}$\left( 0,0\right)$\text{是不是}$f\left( x,y\right) $\text{的极值点}"
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([23,7,0])
        

        text5 = Tex(r"$\lim\limits _{\left( x,y\right) \rightarrow \left( 0,0\right) }\dfrac{f\left( x,y\right) -f\left( 0,0\right) }{x^{3}+y^{3}-3x^{2}-3y^{2}}=1 \Leftrightarrow   \lim\limits _{\left( x,y\right) \rightarrow \left( 0,0\right) }\dfrac{f\left( x,y\right) -f\left( 0,0\right) }{-3x^{2}-3y^{2}}=1$"
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-5,-10,0])
        text6 = Tex(r"$<0$",color=PURE_GREEN
                   ,tex_template=TexTemplateLibrary.ctex).scale(10.0).move_to([15,-18,0])

        text7 = Tex(r"$>0$",color=PURE_GREEN
                   ,tex_template=TexTemplateLibrary.ctex).scale(10.0).next_to(text5,RIGHT,buff=2)

        text8 = Tex(r"$<0$",color=PURE_GREEN
                   ,tex_template=TexTemplateLibrary.ctex).scale(10.0).move_to([15,0,0])
        text9 = Tex(r"$=f\left( 0,0\right) $",color=PURE_RED
                   ,tex_template=TexTemplateLibrary.ctex).scale(10.0).next_to(text8,RIGHT,buff=1)
         #半透明矩阵扩展
        rectangle4=Rectangle(color=BLUE,fill_opacity=0.5,width=1,height=2.8
                            ,stroke_color=YELLOW,stroke_width=0).move_to([23,12,0])
        self.play(
            rectangle4.animate.stretch(35.0,dim=0)
        )

        self.play(Create(text),Create(text1),Create(text2),Create(text3),Create(text4))
        self.play(Create(text5),Create(text6),Create(text7),Create(text8),Create(text9))
        #镜头拉回
          #分析文本
        #text100=MarkupText("<b><i>分析/解：</i></b>",color=PINK).scale(5.0).move_to([-38,12.5,0])
        self.play(FadeIn(dot1),run_time=0.1)
        self.play(FadeIn(dot2),run_time=0.1)
        self.play(FadeIn(dot3),run_time=0.1)

        #题目向上移动
       
        self.wait()